<?php
	class Manageheader extends CI_Model
    {
        public function __construct() {
            parent::__construct();
            $this->load->database();
        }
        
        public function getDanhMuc()
        {
            $this->load->model('nkdefault', 'default');
            $query = $this->db->query("SELECT madanhmuc, tendanhmuc, hienthi FROM danhmuc");
            $this->db->get();           
            if($query->num_rows() > 0)
            {                   
                $arrayResult = array();
                foreach($query->result() as $row)
                {   
                    $danhmuccon = $this->default->loadDanhMucCon($row->madanhmuc);
                    $arrayItem = array("madanhmuc" => $row->madanhmuc, "tendanhmuc"=>$row->tendanhmuc, "hienthi" => $row->hienthi, 'danhmuccon'=> $danhmuccon);                        
                    array_push($arrayResult, $arrayItem);
                }                  
                return $arrayResult;   
            }
            else
                return array();
        }
        
        public function updateDanhMuc($madanhmuc, $typeDanhMuc, $isDisplay)
        {            
            if($madanhmuc != "" && $typeDanhMuc != "" && $isDisplay != "")
            {              
                $data = array('hienthi' => $isDisplay);                
                switch($typeDanhMuc)
                {
                    case 'danhmuc':
                        $this->db->where('madanhmuc', $madanhmuc);
                        $this->db->update('danhmuc', $data);                                               
                    break;
                    case 'danhmuccon':
                        $this->db->where('madanhmuc_con', $madanhmuc);
                        $this->db->update('danhmuccon', $data);                       
                    break;
                }             
                return 'true';
            }
            return 'false';
        }
    }
?>